package flc.ast.adapter;

import android.graphics.Color;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.utils.Content;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.SPUtil;

public class SelLevelAdapter extends StkProviderMultiAdapter<Integer> {

    public SelLevelAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(66));
        addItemProvider(new SelLevelProvider());
    }

    private String levelName = "";//关卡名称，根据关卡名称获取对应关卡数
    private int type = 0;

    public void setLevelName(String levelName) {
        this.levelName = levelName;
    }

    public void setType(int type) {
        this.type = type;
    }

    private class SelLevelProvider extends BaseItemProvider<Integer> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_level;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, Integer integer) {
            int level = SPUtil.getInt(getContext(), levelName, 1);//获取记录的关卡位置
            int currentLevel = baseViewHolder.getPosition() + 1;//当前关卡数
            if (currentLevel < 10) {
                String str = "0" + currentLevel;
                baseViewHolder.setText(R.id.tvSelLevelItemText, str);
            } else {
                baseViewHolder.setText(R.id.tvSelLevelItemText, currentLevel + "");
            }
            if (type==0) {
                if (currentLevel <= level) {
                    baseViewHolder.setImageResource(R.id.ivSelLevelItemImg, R.drawable.js1);
                    baseViewHolder.setTextColor(R.id.tvSelLevelItemText, Color.parseColor("#FFFFFFFF"));
                } else {
                    baseViewHolder.setImageResource(R.id.ivSelLevelItemImg, R.drawable.js2);
                    baseViewHolder.setTextColor(R.id.tvSelLevelItemText, Color.parseColor("#FFA3A3A3"));
                }
            }else {
                if (currentLevel <= level) {
                    baseViewHolder.setImageResource(R.id.ivSelLevelItemImg, R.drawable.j1);
                    baseViewHolder.setTextColor(R.id.tvSelLevelItemText, Color.parseColor("#FFFFFFFF"));
                } else {
                    baseViewHolder.setImageResource(R.id.ivSelLevelItemImg, R.drawable.j2);
                    baseViewHolder.setTextColor(R.id.tvSelLevelItemText, Color.parseColor("#FFA3A3A3"));
                }
            }

        }
    }
}
